package com.lanlian.cayman.bean;

import com.lanlian.cayman.HqMsg;
import com.lanlian.cayman.utils.NumberManager;
import com.lanlian.cayman.utils.TimeUtil;
import com.oms.rpc.protobuf.YsHqInfo;

/**
 * 本地合约
 */
public class MyContractBean {
    public String id;
    public String name;
    /**
     * 最新
     */
    public String last;
    /**
     * 开盘
     */
    public String open;
    /**
     * 收盘
     */
    public String close;
    /**
     * 涨跌
     */
    public String change;
    /**
     * 幅度
     */
    public String chg;
    /**
     * 昨日收盘价
     */
    public String ClosingPrice ;
    /**
     * 昨日结算价
     */
    public String SettlePrice;
    /**
     * 最高价
     */
    public String HighPrice;
    /**
     * 最低价
     */
    public String LowPrice;
    /**
     * 涨停价
     */
    public String LimitUpPrice;
    /**
     * 跌停价
     */
    public String LimitDownPrice;
    /**
     * 总成交量
     */

    public String TotalNum;
    public long vol;
    public long time;
    public double Average;
    /**
     * 最原始的时间
     */
    public String time_test;




    /**
     *转换数据
     */
    public static MyContractBean switchData(HqMsg.YsHqInfo yh,int scale)
    {



        MyContractBean contractList=new MyContractBean();
        contractList.id=yh.getCommodityNo()+yh.getContractNo1();

        contractList.open=NumberManager.getStringNot4or5(yh.getQOpeningPrice()+"","1",scale)+"";

            contractList.last=NumberManager.getStringNot4or5(yh.getQLastPrice()+"","1",scale)+"";


        contractList.chg=NumberManager.getString4or5(yh.getQChangeRate()+"","1",2)+"%";
        contractList.change= NumberManager.getString4or5(yh.getQChangeValue()+"","1",scale);
        contractList.ClosingPrice=NumberManager.getString4or5(yh.getQPreClosingPrice()+"","1",scale);
        contractList.SettlePrice=NumberManager.getString4or5(yh.getQPreSettlePrice()+"","1",scale);
        contractList.HighPrice=NumberManager.getString4or5(yh.getQHighPrice()+"","1",scale);
        contractList.LowPrice=NumberManager.getString4or5(yh.getQLowPrice()+"","1",scale);
        contractList.LimitUpPrice=NumberManager.getString4or5(yh.getQLimitUpPrice()+"","1",scale);
        contractList.LimitDownPrice=NumberManager.getString4or5(yh.getQLimitDownPrice()+"","1",scale);
        contractList.TotalNum=NumberManager.getStringNot4or5(yh.getQTotalQty()+"","1",scale);
        if (yh.getQLastQty() < 0) {
            contractList.vol= 0;
        } else {
            String vols=NumberManager.getStringNot4or5(yh.getQLastQty()+"","1",0);
            contractList.vol=Long.parseLong(vols);
        }

        String time=yh.getTAPIDTSTAMP().substring(0,19);


        String t1=TimeUtil.Date2TimeStamp(time,null);
        long l1=Long.parseLong(t1);
//        long l2=l1%(60);
//        l1=l1-l2+60;

        contractList.time=l1;
        contractList.time_test=time;

        contractList.Average=yh.getQAveragePrice();
        return  contractList;

    }
    /**
     *转换数据
     */
    public static MyContractBean switchData(YsHqInfo yh, int scale)
    {



        MyContractBean contractList=new MyContractBean();
        contractList.id=yh.getCommodityNo()+yh.getContractNo1();

        contractList.open=NumberManager.getString(yh.getQOpeningPrice()+"","1",scale)+"";

        contractList.last=NumberManager.getString(yh.getQLastPrice()+"","1",scale)+"";


        contractList.chg=NumberManager.getString(yh.getQChangeRate()+"","1",2)+"%";
        contractList.change= NumberManager.getString4or5(yh.getQChangeValue()+"","1",scale);
        contractList.ClosingPrice=NumberManager.getString4or5(yh.getQPreClosingPrice()+"","1",scale);
        contractList.SettlePrice=NumberManager.getString4or5(yh.getQPreSettlePrice()+"","1",scale);
        contractList.HighPrice=NumberManager.getString4or5(yh.getQHighPrice()+"","1",scale);
        contractList.LowPrice=NumberManager.getString4or5(yh.getQLowPrice()+"","1",scale);
        contractList.LimitUpPrice=NumberManager.getString4or5(yh.getQLimitUpPrice()+"","1",scale);
        contractList.LimitDownPrice=NumberManager.getString4or5(yh.getQLimitDownPrice()+"","1",scale);
        contractList.TotalNum=NumberManager.getStringNot4or5(yh.getQTotalQty()+"","1",scale);
        String vols=NumberManager.getStringNot4or5(yh.getQLastQty()+"","1",0);
        contractList.vol=Long.parseLong(vols);

        String time=yh.getTAPIDTSTAMP().substring(0,19);

        String t1=TimeUtil.Date2TimeStamp(time,null);
        contractList.time=Long.parseLong(t1);

        contractList.Average=yh.getQAveragePrice();
        return  contractList;

    }

    public MyContractBean() {
    }

    public MyContractBean(String id, String name) {
        this.id = id;
        this.name = name;
    }
}
